package com.wenyu.wenyuyuedu.adapter.personage;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.wenyu.wenyuyuedu.R;
import com.wenyu.wenyuyuedu.base.ListBaseAdapter;
import com.wenyu.wenyuyuedu.bean.personage.MytrendsBean;

import java.util.Date;
import java.util.List;

/**
 * Created by Administrator on 2017/3/23.
 * 他的动态的展示页
 */

public class OtherPublicAdapter extends ListBaseAdapter<MytrendsBean.InfoBean> {
    private Context context;
    private MyViewHolder holderView;

    public OtherPublicAdapter(Context mContext) {
        super(mContext);
        this.context = mContext;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.other_public_item, parent, false);
        return new MyViewHolder(inflate);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        MytrendsBean.InfoBean infoBean = mDataList.get(position);
        holderView = (MyViewHolder) holder;
        if (infoBean != null) {
            String create_time = infoBean.getCreate_time();
            long l = Long.valueOf(create_time) * 1000;
            Date date = new Date(l);
             /*日*/
            int day = date.getDate();
            if(day < 10){
                holderView.mycollect_data.setText( "0" + day + "");
            }else {
                holderView.mycollect_data.setText( day + "");
            }

            /*月*/
            int month = date.getMonth() + 1;
            holderView.mycollect_mouth.setText(month + "月");

            /*书圈的标题*/
            holderView.mycollect_circle_name.setText(infoBean.getTitle());
             /*填充内容的图片*/
            fillContentPhoto(infoBean);
               /*获取帖子的内容*/
            String content = infoBean.getContent();
            if (content.equals("")) {
                holderView.home_all_content.setVisibility(View.GONE);
            }else {
                holderView.home_all_content.setVisibility(View.VISIBLE);
                holderView.home_all_content.setText(content);
            }
        }
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        private TextView mycollect_data;
        private TextView mycollect_mouth;
        private ImageView contentOne;
        private ImageView contentTwo;
        private ImageView contentThree;
        private ImageView contentFour;
        private ImageView contentFive;
        private ImageView iv_allattention_transparency;
        private TextView pictureCount;
        private TextView mycollect_circle_name;
        private TextView home_all_content;

        public MyViewHolder(View itemView) {
            super(itemView);
            mycollect_data = (TextView) itemView.findViewById(R.id.mycollect_data);
            mycollect_mouth = (TextView) itemView.findViewById(R.id.mycollect_mouth);
            home_all_content = (TextView) itemView.findViewById(R.id.home_all_content);
            contentOne = (ImageView) itemView.findViewById(R.id.home_all_content_picture_one);
            contentTwo = (ImageView) itemView.findViewById(R.id.home_all_content_picture_two);
            contentThree = (ImageView) itemView.findViewById(R.id.home_all_content_picture_three);
            contentFour = (ImageView) itemView.findViewById(R.id.home_all_content_picture_four);
            contentFive = (ImageView) itemView.findViewById(R.id.home_all_content_picture_five);
            iv_allattention_transparency = (ImageView) itemView.findViewById(R.id.iv_allattention_transparency);
            pictureCount = (TextView) itemView.findViewById(R.id.home_all_picture_count);
            mycollect_circle_name = (TextView) itemView.findViewById(R.id.mycollect_circle_name);
        }
    }

    private void fillContentPhoto(MytrendsBean.InfoBean infoBean) {
        List<String> images = infoBean.getImages();
        if (images != null) {
            int size = images.size();
            if (size == 1) {
                holderView.contentOne.setVisibility(View.VISIBLE);
                holderView.contentOne.setPadding(0, 0, 0, 0);
                Glide.with(context)
                        .load(images.get(0))
                        .error(R.drawable.nomal_dynamic)
                        .into(holderView.contentOne);
                holderView.contentTwo.setVisibility(View.GONE);
                holderView.contentThree.setVisibility(View.GONE);
                holderView.contentFour.setVisibility(View.GONE);
                holderView.contentFive.setVisibility(View.GONE);
                holderView.iv_allattention_transparency.setVisibility(View.GONE);
                holderView.pictureCount.setVisibility(View.GONE);
            } else if (size == 2) {
                holderView.contentOne.setVisibility(View.VISIBLE);
                holderView.contentTwo.setVisibility(View.VISIBLE);
                Glide.with(context)
                        .load(images.get(0))
                        .error(R.drawable.nomal_dynamic)
                        .into(holderView.contentOne);
                Glide.with(context)
                        .load(images.get(1))
                        .error(R.drawable.nomal_dynamic)
                        .into(holderView.contentTwo);
                holderView.contentThree.setVisibility(View.GONE);
                holderView.contentFour.setVisibility(View.GONE);
                holderView.contentFive.setVisibility(View.GONE);
                holderView.iv_allattention_transparency.setVisibility(View.GONE);
                holderView.pictureCount.setVisibility(View.GONE);
            } else if (size == 3) {
                holderView.contentOne.setVisibility(View.VISIBLE);
                Glide.with(context)
                        .load(images.get(0))
                        .error(R.drawable.nomal_dynamic)
                        .into(holderView.contentOne);
                holderView.contentTwo.setVisibility(View.VISIBLE);
                Glide.with(context)
                        .load(images.get(1))
                        .error(R.drawable.nomal_dynamic)
                        .into(holderView.contentTwo);
                holderView.contentThree.setVisibility(View.VISIBLE);
                Glide.with(context)
                        .load(images.get(2))
                        .error(R.drawable.nomal_dynamic)
                        .into(holderView.contentThree);
                holderView.contentFour.setVisibility(View.GONE);
                holderView.contentFive.setVisibility(View.GONE);
                holderView.iv_allattention_transparency.setVisibility(View.GONE);
                holderView.pictureCount.setVisibility(View.GONE);
            } else if (size == 4) {
                holderView.contentOne.setVisibility(View.VISIBLE);
                Glide.with(context)
                        .load(images.get(0))
                        .error(R.drawable.nomal_dynamic)
                        .into(holderView.contentOne);
                holderView.contentTwo.setVisibility(View.VISIBLE);
                Glide.with(context)
                        .load(images.get(1))
                        .error(R.drawable.nomal_dynamic)
                        .into(holderView.contentTwo);
                holderView.contentThree.setVisibility(View.VISIBLE);
                Glide.with(context)
                        .load(images.get(2))
                        .error(R.drawable.nomal_dynamic)
                        .into(holderView.contentThree);
                holderView.contentFour.setVisibility(View.VISIBLE);
                Glide.with(context)
                        .load(images.get(3))
                        .error(R.drawable.nomal_dynamic)
                        .into(holderView.contentFour);
                holderView.contentFive.setVisibility(View.GONE);
                holderView.iv_allattention_transparency.setVisibility(View.GONE);
                holderView.pictureCount.setVisibility(View.GONE);
            } else if (size == 5) {
                holderView.contentOne.setVisibility(View.VISIBLE);
                Glide.with(context)
                        .load(images.get(0))
                        .error(R.drawable.nomal_dynamic)
                        .into(holderView.contentOne);
                holderView.contentTwo.setVisibility(View.VISIBLE);
                Glide.with(context)
                        .load(images.get(1))
                        .error(R.drawable.nomal_dynamic)
                        .into(holderView.contentTwo);
                holderView.contentThree.setVisibility(View.VISIBLE);
                Glide.with(context)
                        .load(images.get(2))
                        .error(R.drawable.nomal_dynamic)
                        .into(holderView.contentThree);
                holderView.contentFour.setVisibility(View.VISIBLE);
                Glide.with(context)
                        .load(images.get(3))
                        .error(R.drawable.nomal_dynamic)
                        .into(holderView.contentFour);
                holderView.contentFive.setVisibility(View.VISIBLE);
                Glide.with(context)
                        .load(images.get(4))
                        .error(R.drawable.nomal_dynamic)
                        .into(holderView.contentFive);
                holderView.iv_allattention_transparency.setVisibility(View.GONE);
                holderView.pictureCount.setVisibility(View.GONE);
            } else if (size > 5) {
                holderView.contentOne.setVisibility(View.VISIBLE);
                Glide.with(context)
                        .load(images.get(0))
                        .error(R.drawable.nomal_dynamic)
                        .into(holderView.contentOne);
                holderView.contentTwo.setVisibility(View.VISIBLE);
                Glide.with(context)
                        .load(images.get(1))
                        .error(R.drawable.nomal_dynamic)
                        .into(holderView.contentTwo);
                holderView.contentThree.setVisibility(View.VISIBLE);
                Glide.with(context)
                        .load(images.get(2))
                        .error(R.drawable.nomal_dynamic)
                        .into(holderView.contentThree);
                holderView.contentFour.setVisibility(View.VISIBLE);
                Glide.with(context)
                        .load(images.get(3))
                        .error(R.drawable.nomal_dynamic)
                        .into(holderView.contentFour);
                holderView.contentFive.setVisibility(View.VISIBLE);
                Glide.with(context)
                        .load(images.get(4))
                        .error(R.drawable.nomal_dynamic)
                        .into(holderView.contentFive);
                holderView.iv_allattention_transparency.setVisibility(View.VISIBLE);
                holderView.pictureCount.setVisibility(View.VISIBLE);
                holderView.pictureCount.setText("+" + String.valueOf(size - 5));
            }
        }
    }
}
